package com.central.utils.es

import org.apache.commons.pool2.impl.DefaultPooledObject
import org.apache.commons.pool2.{PooledObject, PooledObjectFactory}
import org.apache.http.HttpHost
import org.elasticsearch.client.{RestClient, RestHighLevelClient}

class EsClientPoolFactory extends PooledObjectFactory[RestHighLevelClient] {
  override def makeObject(): PooledObject[RestHighLevelClient] = ???

  override def destroyObject(pooledObject: PooledObject[RestHighLevelClient]): Unit = ???

  override def validateObject(pooledObject: PooledObject[RestHighLevelClient]): Boolean = ???

  override def activateObject(pooledObject: PooledObject[RestHighLevelClient]): Unit = {

  }

  override def passivateObject(pooledObject: PooledObject[RestHighLevelClient]): Unit = {

    var client: RestHighLevelClient = null

    try {
      client = new RestHighLevelClient(RestClient.builder(
        new HttpHost("192.168.5.180", 9200, "http")

      ))
    } catch {
      case e =>
    e.printStackTrace()
    }

    return new DefaultPooledObject[RestHighLevelClient](client)

  }
}
